#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time    : 2018/5/28 14:17
# @Author  : hyang
# @File    : cmd_utils.py
# @Software: PyCharm

import subprocess
from utils.single_log import SingletonLog
logger = SingletonLog().get_logger()


def cmd_exec(cmd):
    """
     执行cmd和shell命令
     返回命令返回值和结果
    :param cmd:
    :return:
    """

    p = subprocess.Popen(cmd,
                         shell=True,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE)

    logger.debug('cmd  >> {} '.format(cmd))
    stdout, stderr = p.communicate()
    if p.returncode != 0:
        return stderr
    return stdout


if __name__ == '__main__':
    pass
